<!--
 * @Description: 
 * @Author: charles
 * @Date: 2021-07-12 10:56:47
 * @LastEditors: charles
 * @LastEditTime: 2021-08-01 14:08:29
-->
<template>
  <div>
    <div class="projects">
      <div class="wrapper">
        <div class="title">研学精选项目</div>
        <div
          class="project"
          v-for="item in articles"
          :key="item.id"
          @click="articleHandler(item.id)"
        >
          <div class="left">
            <img width="100%" :src="item.cover" />
          </div>
          <div class="right">
            <div class="name">{{ item.title }}</div>
            <div class="time">
              {{ item.publishTime | fmtDate }}
            </div>
            <div class="content">阅读次数：{{ item.readTimes }} 点赞次数：{{item.thumpUp}}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { get } from "../utils/request";
export default {
  data() {
    return {
      // 向后台传递的参数
      list:{
        page:1,
        pageSize:10,
        categoryId:this.$route.query.categoryId,
      },
      articles:[],
    };
  },
  // 帧听器
  watch:{
    "$route.query.categoryId":function(){
      this.list.categoryId = this.$route.query.categoryId
      // 刷新页面
      this.findArticleById()
    }
  },
  methods: {
    // 跳转到项目详情页面
    articleHandler(id){
      this.$router.push({
        path:'/article',
        query:{id:id},
      })  
    },
    // 通过categoryId查询资讯信息
    findArticleById(){
      get('/index/article/pageQuery',this.list).then((res)=>{
        if(res.status == 200){
          this.articles = res.data.list
        }else{
          this.$message({
            type:'error',
            message:res.message
          })
        }
      })
    },
  },
  created() {
    this.findArticleById()
  },
};
</script>

<style scope lang="scss">
.projects {
  .wrapper {
    width: 1240px;
    .title {
      font-size: 20px;
      line-height: 4em;
      border-bottom: 1px solid #f4f4f4;
    }
    .project {
      display: flex;
      padding: 1em 0;
      border-bottom: 1px solid #f4f4f4;
      .left {
        width: 300px;
        height: 200px;
        background-color: pink;
        border-radius: 5px;
        overflow: hidden;
      }
      .right {
        flex: 1;
        padding: 0 2em;
        .name {
          font-weight: 500;
          font-size: 15px;
        }
        .time {
          margin: 1em 0;
        }
        .content {
          font-size: 14px;
        }
      }
    }
  }
}
</style>